﻿using System;
using System.ComponentModel.DataAnnotations.Schema;
using Abp.Auditing;
using Abp.Authorization.Users;
using Abp.Extensions;
using KelonProud.Administration.Domain.Organizations;

namespace KelonProud.Administration.Domain.Authorization
{
   [Audited]
    public class User : AbpUser<User>
    {
        [Column("OrganizationUnitId")]
        public virtual long? OrganizationUnitId { get; set; }

        [ForeignKey("OrganizationUnitId")]
        public virtual KelonProudOrganizationUnit  OrganizationUnit { get; set; }

        public User()
        {
            Password = DefaultPassword;
        }

        public const string DefaultPassword = "123456";

        public static string CreateRandomPassword()
        {
            return Guid.NewGuid().ToString("N").Truncate(16);
        }

        public static User CreateTenantAdminUser(int tenantId, string emailAddress)
        {
            var user = new User
            {
                TenantId = tenantId,
                UserName = AdminUserName,
                Name = AdminUserName,
                Surname = AdminUserName,
                EmailAddress = emailAddress
            };

            user.SetNormalizedNames();

            return user;
        }
    }
}
